package com.zj.study.utils.validation.validator.not_element_null;


import com.zj.study.utils.validation.annotation.constraint.NotElementNull;
import com.zj.study.utils.validation.validator.ConstraintValidator;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;

/**
 * @author 赵赳
 * @since 2021/9/3 15:42
 */
public abstract class AbstractNotElementNullValidator<T> implements
    ConstraintValidator<NotElementNull, T> {

  @Override
  final
  public boolean isValid(@NonNull NotElementNull notElementNull, @Nullable T value) {
    return value == null || compare(value);

  }

  /**
   * 校验值是否合法
   *
   * @param value 校验值
   * @return 是否合法
   */
  abstract boolean compare(@NonNull T value);
}
